import AuthorityPlugin from './authority-plugin'
import TabsPagePlugin from './tabs-page-plugin'
import Element from 'element-ui'
import { request, METHOD } from '@/utils/request'
import { formatAmount } from '@/utils/formatter'

const Plugins = {
  install: function (Vue) {
    Vue.use(AuthorityPlugin)
    Vue.use(TabsPagePlugin)
    Vue.use(Element, { size: 'mini' })
    Vue.prototype.$get = function (url, data, config) {
      return request(url, METHOD.GET, data, config);
    }
    Vue.prototype.$post = function (url, data, config) {
      return request(url, METHOD.POST, data, config);
    }
    Vue.prototype.$postParam = function (url, data, config) {
      return request(url, METHOD.POST_PARAM, data, config);
    }
    Vue.prototype.$download = function (url, data) {
      return request(url, METHOD.DOWNLOAD, data);
    }

    // 格式化
    Vue.prototype.$formatAmount = formatAmount

    // 二次确认封装
    Vue.prototype.$doConfirm = function (message, onConfirm, title) {
      this.$confirm(message, title || '提示', {
        // iconClass: 'el-icon-question',
        callback: (action) => {
          if (action == 'confirm') {
            onConfirm()
          }
        }
      })
    }

    // 判断对象是否空
    Vue.prototype.$isEmpty = function (val) {
      if (val === null || val === undefined) {
        return true
      }
      let type = typeof val
      if (type === 'string') {
        return val.trim() === ''
      }
      if (type === 'object') {
        return JSON.stringify(val) === '{}'
      }
      if (type === 'array') {
        return val.length === 0
      }
      return false
    }

    // 判断对象是否不为空
    Vue.prototype.$isNotEmpty = function (val) {
      return !this.$isEmpty(val)
    }
  }
}


export default Plugins
